#define _gam_level_powers_included 1

#if !defined _gam_stock_included
	#include <gam/stock>
#endif


stock bool:isShorterC4Timer(planter){
	if(!isLevelPowers()) return false;
		
	if(gPlayerLevelInfo[planter][WEAPONS_HEGRENADE] > LEVEL_EXPERT)
		return true;
	return false;
}

stock getPlayerVisibility(id, standing){
	if(!isLevelPowers())
		return 100;
		
	new percent = 100;
	new lvlAll[2] ;
	lvlAll[0] = gPlayerLevelInfo[id][WEAPONS_XM1014];
	lvlAll[1] = gPlayerLevelInfo[id][WEAPONS_M3];
	
	new lvl;
	for (new i=0;i<2;i++){
		lvl = lvlAll[i];
		if(lvl != LEVEL_NONE){
			switch(lvl) {
				case LEVEL_BEGINNER, LEVEL_BASIC, LEVEL_ADVANCED: {
					if(standing)
						percent -= ((lvl +1)* 10);
				}
				default:{
					if(standing){
						percent -=40;
					} else { 
						percent -= ((lvl - 2)* 10);
					}
				}
			}
		}
	}
	return percent;
}

stock getUserSpeed(id){
	new percent = 0;
	new allLvl[5];
	allLvl[0] = gPlayerLevelInfo[id][WEAPONS_MAC10];	
	allLvl[1] = gPlayerLevelInfo[id][WEAPONS_UMP45];
	allLvl[2] = gPlayerLevelInfo[id][WEAPONS_MP5NAVY];
	allLvl[3] = gPlayerLevelInfo[id][WEAPONS_TMP];
	allLvl[4] = gPlayerLevelInfo[id][WEAPONS_P90];
	new lvl;
	for(new i=0;i<5;i++){
		lvl = allLvl[i];
		switch(lvl){
			case LEVEL_EXPERT:percent +=2;
			case LEVEL_HITMAN: percent+=3;
			case LEVEL_OWNER: percent+=4;
		}
	}
	return percent;
}

stock getFireSpeed(id){
	new percent = 0;
	new allLvl[5];
	allLvl[0] = gPlayerLevelInfo[id][WEAPONS_MAC10];	
	allLvl[1] = gPlayerLevelInfo[id][WEAPONS_UMP45];
	allLvl[2] = gPlayerLevelInfo[id][WEAPONS_MP5NAVY];
	allLvl[3] = gPlayerLevelInfo[id][WEAPONS_TMP];
	allLvl[4] = gPlayerLevelInfo[id][WEAPONS_P90];
	new lvl;
	for(new i=0;i<5;i++){
		lvl = allLvl[i];
		switch(lvl){
			case LEVEL_BEGINNER:percent +=2;
			case LEVEL_BASIC, LEVEL_ADVANCED, LEVEL_VETERAN, LEVEL_EXPERT: percent+=3;
			case LEVEL_HITMAN, LEVEL_OWNER: percent+=4;
		}
	}
	return percent;
}

stock getUserGravity(id){
	new percent = 0;
	new allLvl[5];
	allLvl[0] = gPlayerLevelInfo[id][WEAPONS_MAC10];	
	allLvl[1] = gPlayerLevelInfo[id][WEAPONS_UMP45];
	allLvl[2] = gPlayerLevelInfo[id][WEAPONS_MP5NAVY];
	allLvl[3] = gPlayerLevelInfo[id][WEAPONS_TMP];
	allLvl[4] = gPlayerLevelInfo[id][WEAPONS_P90];
	new lvl;
	for(new i=0;i<5;i++){
		lvl = allLvl[i];
		switch(lvl){
			case LEVEL_HITMAN: percent+=3;
			case LEVEL_OWNER: percent+=5;
		}
	}
	return percent;
}

stock getUserHpAndArmour(id, &hp, &armour){
	new allLvl[6];
	hp=0;
	armour=0;
	allLvl[0] = gPlayerLevelInfo[id][WEAPONS_AUG];	
	allLvl[1] = gPlayerLevelInfo[id][WEAPONS_GALIL];
	allLvl[2] = gPlayerLevelInfo[id][WEAPONS_FAMAS];
	allLvl[3] = gPlayerLevelInfo[id][WEAPONS_M4A1];
	allLvl[4] = gPlayerLevelInfo[id][WEAPONS_SG552];
	allLvl[5] = gPlayerLevelInfo[id][WEAPONS_AK47];
	new lvl;
	for(new i=0;i<6;i++){
		lvl = allLvl[i];
		switch(lvl){
			case LEVEL_BEGINNER: 	armour+=10;
			case LEVEL_BASIC:	armour+=15;
			case LEVEL_ADVANCED:	{armour+=15; hp+=5;}
			case LEVEL_VETERAN:	{armour+=20; hp+=6;}
			case LEVEL_EXPERT:	{armour+=25; hp+=7;}
			case LEVEL_HITMAN:	{armour+=30; hp+=8;}
			case LEVEL_OWNER:	{armour+=35; hp+=10;}
		}
	}
}

stock Float:getPlayerDamageGive(attacker, wpn, Float:damage, bool:hs){

	new Float:dmg = damage;
	new lvl = gPlayerLevelInfo[attacker][wpn];
	new percent = getPistolAddDmg4AllWeapons(attacker);
	if(percent)
		dmg+= damage *(float(percent)/100.0);
	switch(wpn){
		case WEAPONS_HEGRENADE: {
			switch(lvl){
				case LEVEL_BEGINNER : 	dmg+= (damage* 0.1);
				case LEVEL_BASIC:	dmg+= (damage* 0.2);
				case LEVEL_ADVANCED: 	dmg+= (damage* 0.3);
				case LEVEL_VETERAN:  	dmg+= (damage* 0.15);
				case LEVEL_EXPERT, LEVEL_OWNER:  dmg+= (damage* 0.1);
			}
			return dmg;
		} 
		case WEAPONS_AWP: {
			if(lvl == LEVEL_OWNER)
				return 1000.0;
		}
		case WEAPONS_SCOUT: {
			if( random_num(1, 100) <= 50) //50% chance for instant kill
				return 1000.0; 
		}
		case WEAPONS_P228,WEAPONS_ELITE,WEAPONS_FIVESEVEN,WEAPONS_DEAGLE,WEAPONS_USP,WEAPONS_GLOCK18:{
			if(lvl == LEVEL_OWNER && hs){
				if(random_num(1, 100)<= 30) //30% chance for instant kill if HeadShot
					return 1000.0; 
			}
			dmg += float(getPistolAddDmg(attacker));
		}
	} 
	
	return dmg;
}


stock getPistolAddDmg(id){
	new lvlAll[6];
	lvlAll[0] = gPlayerLevelInfo[id][WEAPONS_P228];
	lvlAll[1] = gPlayerLevelInfo[id][WEAPONS_ELITE];
	lvlAll[2] = gPlayerLevelInfo[id][WEAPONS_FIVESEVEN];
	lvlAll[3] = gPlayerLevelInfo[id][WEAPONS_DEAGLE];
	lvlAll[4] = gPlayerLevelInfo[id][WEAPONS_USP];
	lvlAll[5] = gPlayerLevelInfo[id][WEAPONS_GLOCK18];
	new lvl;
	new dmg = 0;
	for(new i=0;i<6;i++){
		lvl = lvlAll[i];
		switch(lvl){
			case LEVEL_BEGINNER: 	dmg+=2;
			case LEVEL_BASIC : 	dmg+=3;
			case LEVEL_ADVANCED: 	dmg+=4;
		}
	}
	return dmg;
}

stock getPistolAddDmg4AllWeapons(id){
	new lvlAll[6];
	lvlAll[0] = gPlayerLevelInfo[id][WEAPONS_P228];
	lvlAll[1] = gPlayerLevelInfo[id][WEAPONS_ELITE];
	lvlAll[2] = gPlayerLevelInfo[id][WEAPONS_FIVESEVEN];
	lvlAll[3] = gPlayerLevelInfo[id][WEAPONS_DEAGLE];
	lvlAll[4] = gPlayerLevelInfo[id][WEAPONS_USP];
	lvlAll[5] = gPlayerLevelInfo[id][WEAPONS_GLOCK18];
	new lvl;
	new percent = 0;
	for(new i=0;i<6;i++){
		lvl = lvlAll[i];
		switch(lvl){
			case LEVEL_VETERAN: 	percent+=1;
			case LEVEL_EXPERT :	percent+=2;
			case LEVEL_HITMAN, LEVEL_OWNER: percent+=3;
		}
	}
	return percent;
}


stock Float:getPlayerDamageReceive(victim, Float:damage){
	new Float:dmg = damage;
	new lvl =  gPlayerLevelInfo[victim][WEAPONS_AWP];
	new percent = 0;
	switch(lvl){
		case LEVEL_EXPERT:percent = 5;
		case LEVEL_HITMAN, LEVEL_OWNER: percent =10;
	}
	lvl = gPlayerLevelInfo[victim][WEAPONS_SCOUT];
	switch(lvl){
		case LEVEL_EXPERT:	percent += 5;
		case LEVEL_HITMAN: 	percent +=10;
		case LEVEL_OWNER: 	percent += 15;
	}
	if(percent){
		dmg = dmg - (dmg * (float(percent)/100.0));
	}
	return dmg;
}

stock getFreeScout(id) {
	new percent = 0;
	new lvl = gPlayerLevelInfo[id][WEAPONS_AWP];
	switch(lvl){
		case LEVEL_BEGINNER: 	percent += 15;
		case LEVEL_BASIC: 	percent += 20;
		case LEVEL_ADVANCED: 	percent += 35;
		case LEVEL_VETERAN, LEVEL_EXPERT, LEVEL_HITMAN: percent += 50;
		case LEVEL_OWNER: 	return 100;
	}
	lvl = gPlayerLevelInfo[id][WEAPONS_SCOUT];
	switch(lvl){
		case LEVEL_BEGINNER: 	percent += 15;
		case LEVEL_BASIC: 	percent += 20;
		case LEVEL_ADVANCED: 	percent += 35;
		case LEVEL_VETERAN, LEVEL_EXPERT, LEVEL_HITMAN: percent += 50;
		case LEVEL_OWNER: 	return 100;
	}
	return percent;
}

stock getDropWeaponChance(id){
	new lvlAll[6];
	lvlAll[0] = gPlayerLevelInfo[id][WEAPONS_P228];
	lvlAll[1] = gPlayerLevelInfo[id][WEAPONS_ELITE];
	lvlAll[2] = gPlayerLevelInfo[id][WEAPONS_FIVESEVEN];
	lvlAll[3] = gPlayerLevelInfo[id][WEAPONS_DEAGLE];
	lvlAll[4] = gPlayerLevelInfo[id][WEAPONS_USP];
	lvlAll[5] = gPlayerLevelInfo[id][WEAPONS_GLOCK18];
	new lvl;
	new percent = 0;
	for(new i=0;i<6;i++){
		lvl = lvlAll[i];
		switch(lvl){
			case LEVEL_EXPERT :	percent+=1;
			case LEVEL_HITMAN:	percent +=2;
			case LEVEL_OWNER: 	percent+=3;
		}
	}
	return percent;
}
